<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>奖励设置</title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <link rel="stylesheet" href="css/ydui.css?rev=@@hash" />
    <link rel="stylesheet" href="css/demo.css" />
    <script src="js/ydui.flexible.js"></script>
</head>

<body>
    <section class="g-flexview">
        <section class="g-scrollview">
            <div class="m-cell demo-small-pitch">
                <div class="cell-item">
                    <div class="cell-left">奖励人数</div>
                    <div class="cell-right">
                        <span class="m-spinner"><!-- 添加data-ydui-spinner属性并添加参数即可 -->
                                <a href="javascript:;" id="j_Del" class="J_Del"></a>
                                <input type="text" id="j_input" class="J_Input" value="1" onfocus="this.blur()" placeholder=""/>
                                <a href="javascript:;" class="J_Add" id="j_add"></a>
                        </span>
                    </div>
                </div>
                <div class="cell-item" id="mr_k">
                    <div class="cell-left">第1名</div>
                    <div class="cell-right">
                        <input type="number" class="cell-input" placeholder="请输入奖励百分比,例:0.5" autocomplete="off" />
                    </div>
                </div>
            </div>
            <div class="m-button">
                <button type="button" id="saveBtn" onclick="saveBtn()" class="btn-block btn-primary">保存</button>
            </div>
        </section>

    </section>
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="js/layer/layer.js"></script>
    <script>
        /* 获取头部信息 */
        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return r[2];
            }
        };
        var arrStr = GetQueryString('token');
        console.log(arrStr);
        var arrt = arrStr.split(',');
        if (arrt != 'undefined' && arrt.length > 0) {
            $("#j_input").val(arrt.length);
            $('#mr_k').remove();
            for (var i = 0; i < arrt.length; i++) {
                var ss = '<div class="cell-item"><div class = "cell-left" >第' + parseInt(i + 1) + '名 </div><div class = "cell-right" ><input type = "number"  value="' + arrt[i] + '"  class = "cell-input" placeholder = "请输入奖励百分比,例:0.5" autocomplete = "off" / ></div> </div>'
                $('.m-cell').append(ss);
            }
        }

        function saveBtn() {
            var arr = [];
            var aaarr = $("input[ type='number']");
            var strAdd = 0;
            var isGo = true;
            var addNum = 0.0;
            $("input[ type='number']").each(function() {
                if ($(this).val().length != 0) {
                    if ($(this).val() >= 1) {
                        isGo = false;
                        layer.msg("奖励百分比必须小于1");
                        return;
                    }
                    addNum += parseFloat($(this).val() + '');
                    arr.push($(this).val());
                    strAdd++;
                }
            });
            console.log(addNum.toFixed(2));
            if (!isGo) {
                return;
            }
            if (addNum >= 1) {
                layer.msg("奖励百分比总和不能大于1");
                return;
            }
            if (strAdd != aaarr.length) {
                layer.msg("请填写所有奖励百分比内容");
                return;
            }
            var awardNum = $(" input[ type='number']").val();
            console.log(arr);
            if (awardNum == "") {
                layer.msg("请填写奖励百分比");
                return false;
            }
            parent.backBlock({
                'awardNum': arr + '',
            });
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        };

        $(function() {
            /* 点击加号 */
            $('#j_add ').on('click ', function() {
                var num = $("#j_input").val();
                if (num < 100) {
                    var addNum = parseInt(num) + 1;
                    $("#j_input").val(addNum);
                    console.log(addNum);
                    var ss = '<div class="cell-item"><div class = "cell-left" >第' + parseInt(addNum) + '名 </div><div class = "cell-right" ><input type = "number"  needtype="' + addNum + '"  class = "cell-input" placeholder = "请输入奖励百分比,例:0.5" autocomplete = "off" / ></div> </div>'
                    $('.m-cell').append(ss);
                } else {
                    return;
                }
            });
            /* 点击减号 */
            $('#j_Del ').on('click ', function() {
                var num = $("#j_input").val();
                if (num > 1) {
                    $("#j_input").val(parseInt(num) - 1);
                    var delNum = parseInt(num) - 1;
                    console.log(delNum);
                    $('.cell-item:last-child').remove();
                } else {
                    return;
                }

            });
            //保存按钮

        });
    </script>
</body>

</html>